{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[89, 95, 61, 80, 86, 70, 63, 63, 63, 88, 85, 76, 68, 83, 65, 84,\n",
       "         87, 77, 71, 67, 69, 65, 79, 92, 91, 77, 95, 78, 75, 97, 62, 91,\n",
       "         85, 67, 92, 96, 69, 93, 67, 61, 71, 70, 82, 65, 75, 71, 78, 85,\n",
       "         91, 68],\n",
       "        [93, 92, 64, 82, 94, 64, 89, 66, 60, 98, 65, 72, 62, 65, 62, 99,\n",
       "         67, 89, 78, 83, 64, 84, 86, 97, 72, 98, 92, 76, 91, 94, 77, 90,\n",
       "         79, 70, 61, 67, 67, 67, 64, 84, 71, 96, 72, 78, 67, 64, 61, 88,\n",
       "         85, 86],\n",
       "        [81, 67, 90, 93, 84, 90, 85, 90, 82, 89, 83, 82, 89, 64, 65, 79,\n",
       "         62, 89, 76, 69, 97, 69, 93, 92, 96, 90, 69, 81, 63, 70, 91, 85,\n",
       "         74, 95, 91, 82, 80, 97, 89, 83, 89, 64, 91, 66, 61, 96, 75, 63,\n",
       "         99, 93]],\n",
       "\n",
       "       [[68, 72, 92, 67, 69, 96, 81, 96, 96, 96, 72, 84, 90, 97, 84, 71,\n",
       "         97, 73, 91, 84, 78, 74, 77, 60, 92, 86, 98, 77, 96, 61, 83, 98,\n",
       "         72, 87, 79, 79, 75, 62, 94, 64, 71, 70, 71, 72, 98, 97, 68, 74,\n",
       "         79, 88],\n",
       "        [99, 81, 76, 61, 92, 75, 67, 81, 75, 96, 61, 65, 91, 83, 96, 79,\n",
       "         79, 84, 80, 65, 84, 63, 74, 68, 66, 76, 99, 87, 63, 61, 77, 99,\n",
       "         91, 74, 96, 88, 71, 88, 61, 93, 76, 79, 94, 68, 79, 85, 88, 86,\n",
       "         97, 87],\n",
       "        [81, 89, 77, 96, 62, 81, 73, 97, 92, 88, 92, 70, 74, 98, 87, 87,\n",
       "         71, 72, 75, 74, 67, 97, 85, 77, 88, 63, 74, 72, 92, 61, 84, 71,\n",
       "         67, 71, 60, 77, 83, 99, 74, 68, 72, 82, 72, 95, 86, 70, 96, 90,\n",
       "         77, 64]],\n",
       "\n",
       "       [[76, 75, 81, 88, 86, 83, 61, 63, 61, 63, 96, 93, 60, 92, 91, 92,\n",
       "         83, 89, 67, 67, 74, 94, 92, 74, 68, 64, 75, 71, 95, 71, 94, 88,\n",
       "         83, 90, 96, 78, 80, 64, 91, 83, 74, 85, 76, 90, 64, 76, 85, 64,\n",
       "         73, 68],\n",
       "        [62, 71, 94, 88, 82, 95, 63, 67, 95, 88, 62, 75, 60, 60, 79, 62,\n",
       "         67, 73, 79, 78, 71, 63, 97, 73, 98, 72, 78, 89, 90, 60, 89, 60,\n",
       "         62, 80, 74, 87, 86, 65, 81, 90, 98, 89, 97, 74, 69, 85, 60, 68,\n",
       "         78, 88],\n",
       "        [97, 81, 72, 96, 86, 98, 93, 64, 68, 81, 90, 72, 83, 69, 97, 70,\n",
       "         71, 95, 86, 96, 74, 73, 63, 97, 84, 64, 65, 71, 67, 85, 90, 93,\n",
       "         70, 73, 83, 71, 86, 87, 86, 81, 73, 86, 91, 78, 75, 82, 81, 90,\n",
       "         93, 77]],\n",
       "\n",
       "       [[92, 96, 68, 98, 86, 94, 85, 72, 61, 61, 66, 60, 70, 82, 62, 65,\n",
       "         72, 67, 83, 61, 83, 83, 84, 73, 81, 77, 62, 60, 99, 86, 89, 96,\n",
       "         73, 80, 72, 83, 74, 80, 69, 73, 73, 66, 91, 71, 62, 71, 78, 90,\n",
       "         99, 96],\n",
       "        [95, 87, 77, 88, 81, 92, 65, 68, 72, 77, 94, 96, 95, 81, 60, 80,\n",
       "         84, 67, 99, 71, 60, 98, 82, 70, 69, 93, 89, 72, 65, 90, 97, 62,\n",
       "         67, 86, 94, 62, 63, 78, 74, 84, 71, 72, 94, 85, 60, 75, 68, 86,\n",
       "         86, 73],\n",
       "        [72, 84, 99, 71, 72, 60, 91, 91, 88, 77, 73, 73, 76, 70, 77, 79,\n",
       "         62, 96, 82, 85, 73, 63, 68, 61, 65, 67, 79, 91, 79, 94, 65, 72,\n",
       "         92, 79, 71, 75, 95, 65, 90, 90, 80, 86, 80, 98, 64, 91, 89, 85,\n",
       "         91, 60]],\n",
       "\n",
       "       [[89, 70, 75, 64, 77, 62, 60, 90, 62, 69, 60, 76, 70, 95, 95, 87,\n",
       "         79, 81, 93, 67, 83, 63, 65, 71, 60, 75, 97, 73, 84, 68, 91, 84,\n",
       "         84, 65, 75, 86, 63, 83, 70, 79, 64, 90, 94, 97, 76, 72, 96, 74,\n",
       "         87, 95],\n",
       "        [78, 77, 93, 79, 66, 86, 96, 85, 90, 75, 64, 86, 93, 64, 85, 63,\n",
       "         99, 89, 87, 65, 85, 92, 99, 87, 71, 83, 69, 99, 67, 99, 93, 89,\n",
       "         99, 60, 68, 66, 86, 65, 98, 70, 78, 73, 88, 77, 87, 77, 72, 82,\n",
       "         68, 99],\n",
       "        [68, 88, 97, 71, 79, 87, 93, 95, 66, 92, 96, 98, 66, 88, 70, 70,\n",
       "         86, 76, 68, 79, 66, 62, 63, 95, 60, 93, 60, 86, 81, 81, 94, 67,\n",
       "         99, 88, 98, 83, 76, 83, 76, 70, 84, 94, 61, 73, 79, 89, 91, 90,\n",
       "         97, 97]],\n",
       "\n",
       "       [[88, 86, 99, 69, 63, 90, 73, 78, 92, 96, 91, 68, 89, 68, 88, 80,\n",
       "         70, 66, 83, 68, 91, 74, 95, 62, 79, 70, 81, 99, 80, 94, 75, 81,\n",
       "         78, 79, 94, 65, 60, 63, 74, 74, 69, 87, 66, 65, 69, 94, 72, 71,\n",
       "         90, 60],\n",
       "        [66, 84, 75, 68, 78, 81, 74, 94, 96, 93, 96, 61, 98, 74, 73, 71,\n",
       "         93, 69, 81, 74, 63, 73, 64, 65, 71, 76, 85, 87, 76, 86, 97, 78,\n",
       "         76, 79, 67, 93, 71, 97, 75, 66, 88, 71, 93, 75, 95, 80, 72, 71,\n",
       "         99, 62],\n",
       "        [95, 85, 82, 64, 67, 77, 93, 75, 94, 98, 83, 61, 96, 96, 92, 76,\n",
       "         78, 96, 80, 69, 67, 76, 83, 68, 83, 64, 79, 62, 98, 72, 94, 87,\n",
       "         79, 68, 79, 88, 61, 77, 79, 92, 76, 61, 87, 72, 74, 84, 81, 76,\n",
       "         78, 64]]])"
      ]
     },
     "execution_count": 146,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "score = np.random.randint(60, 100, size = (6, 50, 3))\n",
    "score = score.reshape(6, 3, 50)\n",
    "score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 152,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[263, 254, 215, 255, 264, 224, 237, 219, 205, 275, 233, 230,\n",
       "         219, 212, 192, 262, 216, 255, 225, 219, 230, 218, 258, 281,\n",
       "         259, 265, 256, 235, 229, 261, 230, 266, 238, 232, 244, 245,\n",
       "         216, 257, 220, 228, 231, 230, 245, 209, 203, 231, 214, 236,\n",
       "         275, 247]],\n",
       "\n",
       "       [[248, 242, 245, 224, 223, 252, 221, 274, 263, 280, 225, 219,\n",
       "         255, 278, 267, 237, 247, 229, 246, 223, 229, 234, 236, 205,\n",
       "         246, 225, 271, 236, 251, 183, 244, 268, 230, 232, 235, 244,\n",
       "         229, 249, 229, 225, 219, 231, 237, 235, 263, 252, 252, 250,\n",
       "         253, 239]],\n",
       "\n",
       "       [[235, 227, 247, 272, 254, 276, 217, 194, 224, 232, 248, 240,\n",
       "         203, 221, 267, 224, 221, 257, 232, 241, 219, 230, 252, 244,\n",
       "         250, 200, 218, 231, 252, 216, 273, 241, 215, 243, 253, 236,\n",
       "         252, 216, 258, 254, 245, 260, 264, 242, 208, 243, 226, 222,\n",
       "         244, 233]],\n",
       "\n",
       "       [[259, 267, 244, 257, 239, 246, 241, 231, 221, 215, 233, 229,\n",
       "         241, 233, 199, 224, 218, 230, 264, 217, 216, 244, 234, 204,\n",
       "         215, 237, 230, 223, 243, 270, 251, 230, 232, 245, 237, 220,\n",
       "         232, 223, 233, 247, 224, 224, 265, 254, 186, 237, 235, 261,\n",
       "         276, 229]],\n",
       "\n",
       "       [[235, 235, 265, 214, 222, 235, 249, 270, 218, 236, 220, 260,\n",
       "         229, 247, 250, 220, 264, 246, 248, 211, 234, 217, 227, 253,\n",
       "         191, 251, 226, 258, 232, 248, 278, 240, 282, 213, 241, 235,\n",
       "         225, 231, 244, 219, 226, 257, 243, 247, 242, 238, 259, 246,\n",
       "         252, 291]],\n",
       "\n",
       "       [[249, 255, 256, 201, 208, 248, 240, 247, 282, 287, 270, 190,\n",
       "         283, 238, 253, 227, 241, 231, 244, 211, 221, 223, 242, 195,\n",
       "         233, 210, 245, 248, 254, 252, 266, 246, 233, 226, 240, 246,\n",
       "         192, 237, 228, 232, 233, 219, 246, 212, 238, 258, 225, 218,\n",
       "         267, 186]]])"
      ]
     },
     "execution_count": 152,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "score_3tests = np.sum(score, axis=1)\n",
    "score_3tests = score_3tests.reshape(6, 1, 50)\n",
    "score_3tests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 153,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[2, 2, 2, 1, 1, 1, 1, 1, 2, 1, 2, 2, 1, 2, 1, 2, 1, 1, 1, 1, 2,\n",
       "         2, 2, 1, 1, 2, 1, 2, 1, 2, 1, 1, 1, 2, 1, 2, 1, 2, 1, 1, 2, 2,\n",
       "         2, 2, 1, 2, 2, 1, 1, 1]],\n",
       "\n",
       "       [[1, 1, 2, 2, 1, 2, 1, 2, 1, 2, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 2,\n",
       "         1, 2, 1, 1, 2, 1, 2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 1, 2, 2,\n",
       "         1, 2, 1, 1, 2, 1, 1, 1]],\n",
       "\n",
       "       [[1, 1, 2, 1, 1, 2, 1, 1, 1, 2, 1, 2, 1, 1, 2, 2, 1, 1, 1, 1, 1,\n",
       "         1, 1, 2, 1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1,\n",
       "         2, 1, 2, 1, 2, 2, 1, 2]],\n",
       "\n",
       "       [[2, 2, 2, 1, 1, 1, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 2, 1, 1, 1,\n",
       "         2, 1, 2, 1, 2, 1, 2, 2, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2,\n",
       "         1, 2, 1, 2, 1, 2, 2, 2]],\n",
       "\n",
       "       [[1, 2, 2, 1, 2, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 1, 1, 2, 1, 2, 1,\n",
       "         2, 1, 2, 2, 2, 2, 2, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1,\n",
       "         2, 1, 1, 2, 1, 1, 2, 1]],\n",
       "\n",
       "       [[1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1,\n",
       "         1, 1, 2, 2, 1, 2, 1, 2, 1, 1, 1, 2, 2, 1, 2, 2, 2, 1, 1, 1, 1,\n",
       "         1, 2, 2, 2, 2, 1, 1, 1]]])"
      ]
     },
     "execution_count": 153,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1: female,  2: male\n",
    "sex = np.random.randint(1, 3, size = (6, 50))\n",
    "sex = sex.reshape(6, 1, 50)\n",
    "sex"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 154,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[89, 95, 61, ..., 85, 91, 68],\n",
       "        [93, 92, 64, ..., 88, 85, 86],\n",
       "        [81, 67, 90, ..., 63, 99, 93],\n",
       "        [ 2,  2,  2, ...,  1,  1,  1]],\n",
       "\n",
       "       [[68, 72, 92, ..., 74, 79, 88],\n",
       "        [99, 81, 76, ..., 86, 97, 87],\n",
       "        [81, 89, 77, ..., 90, 77, 64],\n",
       "        [ 1,  1,  2, ...,  1,  1,  1]],\n",
       "\n",
       "       [[76, 75, 81, ..., 64, 73, 68],\n",
       "        [62, 71, 94, ..., 68, 78, 88],\n",
       "        [97, 81, 72, ..., 90, 93, 77],\n",
       "        [ 1,  1,  2, ...,  2,  1,  2]],\n",
       "\n",
       "       [[92, 96, 68, ..., 90, 99, 96],\n",
       "        [95, 87, 77, ..., 86, 86, 73],\n",
       "        [72, 84, 99, ..., 85, 91, 60],\n",
       "        [ 2,  2,  2, ...,  2,  2,  2]],\n",
       "\n",
       "       [[89, 70, 75, ..., 74, 87, 95],\n",
       "        [78, 77, 93, ..., 82, 68, 99],\n",
       "        [68, 88, 97, ..., 90, 97, 97],\n",
       "        [ 1,  2,  2, ...,  1,  2,  1]],\n",
       "\n",
       "       [[88, 86, 99, ..., 71, 90, 60],\n",
       "        [66, 84, 75, ..., 71, 99, 62],\n",
       "        [95, 85, 82, ..., 76, 78, 64],\n",
       "        [ 1,  1,  2, ...,  1,  1,  1]]])"
      ]
     },
     "execution_count": 154,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "_complex = np.concatenate([score, sex], axis=1)\n",
    "_complex"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 155,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "所有班級女生的成績統計量\n",
      "===========\n",
      "科目 0\n",
      "=========\n",
      "最小值: 60\n",
      "最大值: 99\n",
      "平均值: 79.33136094674556\n",
      "中位數: 80.0\n",
      "標準差: 11.652118121942705\n",
      "\n",
      "科目 1\n",
      "=========\n",
      "最小值: 60\n",
      "最大值: 99\n",
      "平均值: 78.68639053254438\n",
      "中位數: 78.0\n",
      "標準差: 12.251887597167963\n",
      "\n",
      "科目 2\n",
      "=========\n",
      "最小值: 60\n",
      "最大值: 99\n",
      "平均值: 80.04733727810651\n",
      "中位數: 81.0\n",
      "標準差: 11.019515045809564\n",
      "\n",
      "所有班級男生的成績統計量\n",
      "===========\n",
      "科目 0\n",
      "=========\n",
      "最小值: 60\n",
      "最大值: 99\n",
      "平均值: 77.48091603053435\n",
      "中位數: 75.0\n",
      "標準差: 11.111063975710806\n",
      "\n",
      "科目 1\n",
      "=========\n",
      "最小值: 60\n",
      "最大值: 99\n",
      "平均值: 79.68702290076335\n",
      "中位數: 78.0\n",
      "標準差: 11.344759673651561\n",
      "\n",
      "科目 2\n",
      "=========\n",
      "最小值: 60\n",
      "最大值: 99\n",
      "平均值: 80.61068702290076\n",
      "中位數: 81.0\n",
      "標準差: 11.36122541979737\n",
      "\n"
     ]
    }
   ],
   "source": [
    "sex_name = ['女生', '男生']\n",
    "\n",
    "for sex_id in range(len(sex_name)):\n",
    "    print(f'所有班級{sex_name[sex_id]}的成績統計量\\n===========')\n",
    "    for test_id in range(3):\n",
    "        print(f'科目 {test_id}\\n=========')\n",
    "        # 分性別\n",
    "        cond = (_complex == sex_id + 1)\n",
    "        # 篩選該科、該性別的成績\n",
    "        female_scores = _complex[:, test_id][cond[:, 3]]\n",
    "        print(f'最小值: {female_scores.min()}\\n最大值: {female_scores.max()}\\n平均值: {female_scores.mean()}\\n中位數: {np.median(female_scores)}\\n標準差: {female_scores.std()}\\n')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
